<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="80px">
      <el-form-item label="采购单号" prop="caigouno">
        <el-input v-model="queryParams.caigouno" placeholder="请输入采购单号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="供应商" prop="supplierName">
        <el-input v-model="queryParams.supplierName" placeholder="请输入制单人"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="制单人" prop="createBy">
        <el-input v-model="queryParams.createBy" placeholder="请输入制单人"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品编码" prop="goodsCode">
        <el-input v-model="queryParams.goodsCode" placeholder="请输入产品编码"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品名称" prop="goodsName">
        <el-input v-model="queryParams.goodsName" placeholder="请输入产品名称"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品型号" prop="goodModel">
        <el-input v-model="queryParams.goodModel" placeholder="请输入产品型号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--  <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                      v-hasPermi="['develop:LvRuku:add']">新增</el-button>
          </el-col>
          <el-col :span="1.5">
              <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                      @click="handleUpdate" v-hasPermi="['develop:LvRuku:edit']">修改</el-button>
          </el-col>
          <el-col :span="1.5">
              <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
                  <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                             v-hasPermi="['develop:LvRuku:remove']">删除</el-button>
              </el-popconfirm>
          </el-col>
          <el-col :span="1.5">
              <el-button type="warning" plain icon="el-icon-download" size="mini"
                      @click="handleExport" v-hasPermi="['develop:LvRuku:export']">导出</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>-->

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
              :max-height="tableMaxHeight">
      <el-table-column align="center" label="序号" type="index" width="50">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column sortable align="center"  label="采购单号" prop="caigouno">
        <template slot-scope="scope">
          <el-tooltip class="item" content="点击查看详情" effect="dark" placement="left-start">
            <span @click="caigouDeatil(scope.row)" style="color: #00afff;cursor:pointer;">
              {{scope.row.caigouno}}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column sortable align="center" label="供应商" prop="supplierName" />
      <el-table-column sortable align="center" label="制单人" prop="createBy" />
      <el-table-column sortable align="center" label="产品编码" prop="goodsCode" />
      <el-table-column sortable align="center" label="产品名称" prop="goodsName"/>
      <el-table-column sortable align="center" label="产品型号" prop="goodModel" />
      <el-table-column sortable align="center" label="订单数量" prop="orderCount" />
      <el-table-column sortable align="center" label="请购数量" prop="pleaseBuyCount" />
      <el-table-column sortable align="center" label="采购单价" prop="goodsBuyPrice" />
      <el-table-column sortable align="center" label="采购数量" prop="shengyu" />
      <el-table-column sortable align="center" label="采购总价" prop="goodsBuyTotal" />
      <el-table-column sortable align="center" label="产品状态" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.goods_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column sortable align="center" label="备注" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-document" @click="showGoodsSaleDoDetail(scope.row)">查看请购明细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

    <PurchaseDetailsFormList ref="PurchaseDetailsFormList"></PurchaseDetailsFormList>
    <showGoodsSaleDoDetail-form ref="showGoodsSaleDoDetailForm" @ok="getList"></showGoodsSaleDoDetail-form>
  </div>
</template>

<script>
  import {deleteAction, getAction} from '@/api/manage'
  import ShowGoodsSaleDoDetailForm from '@/views/develop/pleaseBuy/ShowGoodsSaleDoDetailForm'
  import PurchaseDetailsFormList from '@/views/develop/pleaseBuy/module/PurchaseDetailsFormList'

  export default {
    name: "LvRukuList",
    dicts: ['churuku_type', 'caigou_type', 'storage_state','ruku_source'],
    components: {
      ShowGoodsSaleDoDetailForm,
      PurchaseDetailsFormList,
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 入库单表格数据
        dataList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          code: null,
          name: null,
          mainId: null,
          nos: null,
          caigouno: null,
          goodsCode: null,
          goodsName: null,
          goodModel: null,
          createBy: null,
          supplierName: null,
        },
        url: {
          list: '/goodsSalebuyall/goodsSalebuyall/list',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      this.queryParams.source = this.$route.query.source;
      this.getList();
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight)
    },
    methods: {
      showGoodsSaleDoDetail(row) {
        this.$refs.showGoodsSaleDoDetailForm.show(row);
      },
      caigouDeatil(row){
        this.$refs.PurchaseDetailsFormList.openDialog(row);
      },
      /** 查询入库单列表 */
      getList() {
        this.loading = true;
        getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.$refs.form.handleAdd();
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.$refs.form.handleUpdate(row);
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download(this.url.export, {
          ...this.queryParams
        }, `lvRuku_${new Date().getTime()}.xlsx`)
      },
    }
  };
</script>
